package com.prototype.prototypepattern.deep;

import java.io.*;
import java.util.List;

/**
 * @Classname QiTianDaSheng
 * @Description 齐天大圣类
 * @Date 2019/11/22 0022 12:36
 * @Created by 埔枘
 */
public class QiTianDaSheng implements Cloneable, Serializable {

    public String name;
    public int age;
    private List<String> shuiguo;

    public List<String> getShuiguo() {
        return shuiguo;
    }

    public void setShuiguo(List<String> shuiguo) {
        this.shuiguo = shuiguo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    protected Object clone(){
        return this.deepClone();
    }

    public Object deepClone(){
        try{
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(this);
            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);
            QiTianDaSheng copy = (QiTianDaSheng)ois.readObject();
            return copy;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

}
